package com.astrakit.common.exception;

import com.astrakit.common.api.ApiResponse;
import com.astrakit.common.api.ErrorCode;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * Created with IntelliJ IDEA.
 * Description:做渐进主义的改良派,不做完美主义的速成派
 * User: XALEXC
 * Date: 2025-08-20
 * Time: 21:24
 */

@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(BusinessException.class)
    public ApiResponse<?> handleBusinessException(BusinessException e) {
        return ApiResponse.error(e.getCode(), e.getMessage());
    }

    @ExceptionHandler(Exception.class)
    public ApiResponse<?> handleException(Exception e) {
        return ApiResponse.error(ErrorCode.SERVER_ERROR);
    }
}

